package com.hb.common.exception;


import com.hb.common.enums.ResponseErrorEnums;

/**
 * 通用异常
 *
 * @author hb
 * @date 2023/04/23
 */
public class BaseException extends RuntimeException{
	private static final long serialVersionUID = 1L;
	/**
	 * 错误代码
	 */
	protected int code;
	/**
	 * 返回的异常信息
	 * <pre>
	 * 通过restful接口返回到前端的信息
	 * </pre>
	 */
	protected String message;
	/**
	 * 打印的异常信息
	 * <pre>
	 * 通过控制台或者输出到统一日志平台的信息
	 * </pre>
	 */
	protected String detailMessage;

	public BaseException() {
		super();
	}

	public BaseException(Throwable cause) {
		super(cause);
	}

	public BaseException(String message) {
		super(message);
		this.message = message;
	}

	public BaseException(String message, Throwable cause) {
		super(message, cause);
		this.message = message;
	}

	public BaseException(ResponseErrorEnums enums) {
		super();
		this.code = enums.getCode();
		this.message = enums.getMsg();
	}

	public BaseException(ResponseErrorEnums enums, String detailMessage) {
		super();
		this.code = enums.getCode();
		this.message = enums.getMsg();
		this.detailMessage = detailMessage;
	}

    public BaseException(ResponseErrorEnums enums, Throwable e) {
        super(e);
        this.code = enums.getCode();
        this.message = enums.getMsg();
    }

	public int getCode() {
		return code;
	}

	public void setCode(int code) {
		this.code = code;
	}

	@Override
	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public String getDetailMessage() {
		return detailMessage;
	}

	public void setDetailMessage(String detailMessage) {
		this.detailMessage = detailMessage;
	}

	@Override
	public Throwable fillInStackTrace() {
		return this;
	}
}
